package Reeks5.VanRansbeeck.Kevin.Model;

public class Kaart {
    private Waarde waarde;
    private Type type;

    public Kaart(Type t, Waarde w) {
        this.setType(t);
        this.setWaarde(w);
    }

    public Type getType() {
        return type;
    }

    private void setType(Type type) {
        if (type != null) {
            this.type = type;
        } else {
            throw new NullPointerException("Type == null");
        }
    }

    public Waarde getWaarde() {
        return waarde;
    }

    private void setWaarde(Waarde waarde) {
        if(waarde != null) {
            this.waarde = waarde;
        } else {
            throw new NullPointerException("Waarde == null");
        }
    }

    @Override
    public boolean equals(Object obj) {
        if(obj == null) {
            throw new NullPointerException("Obj == null");
        }
        if(this == obj) {
            return true;
        }
        if (!(obj instanceof Kaart)) {
            return false;
        }

        try {
            Kaart kaart = (Kaart)obj;
            return this.getWaarde() == kaart.getWaarde() && this.getType() == kaart.getType();
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 29 * hash + (this.waarde != null ? this.waarde.hashCode() : 0);
        hash = 29 * hash + (this.type != null ? this.type.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        String ret = "";
        if(this.waarde != null) {
            switch(this.waarde){
                case Twee:	ret += " 2";break;
                case Drie:	ret += " 3";break;
                case Vier:	ret += " 4";break;
                case Vijf: 	ret += " 5";break;
                case Zes:	ret += " 6";break;
                case Zeven:	ret += " 7";break;
                case Acht:	ret += " 8";break;
                case Negen: 	ret += " 9";break;
                case Tien:	ret += "10";break;
                case Boer:	ret += " J";break;
                case Dame:	ret += " Q";break;
                case Koning: 	ret += " K";break;
                case Aas:	ret += " A";break;
                default:	ret += "**";break;
                }
        }

        if(this.type != null) {
            switch(this.type){
                case Klaveren:  ret += " C";break;
                case Ruiten:	ret += " D";break;
                case Harten:	ret += " H";break;
                case Schoppen: 	ret += " S";break;
                default:	ret += " **";break;
            }
        }
        return ret;
    }
    
    public void print() {
        System.out.println(this.toString());
    }
}
